import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import {getLognUserUsingGet} from "@/api/userController";

export const useLoginUserStore = defineStore('LoginUser', () => {
  const loginUser = ref<API.LoginUserVO>({
    userName: '未登录',
    userRole: ''
  })

  /**
   * 远程获取登录用户信息
   * @param newUser
   */
  const getLoginUser = async () => {
    const res = await getLognUserUsingGet()
    if (res.data.code === 0 && res.data.data){
      loginUser.value = res.data.data
    }

  }
  const setLoginUser = (newUser: any) => {
    loginUser.value = newUser
  }
  return { loginUser, setLoginUser, getLoginUser }
})
